<?php

namespace common\models;

use Yii;
use builder\behaviors\DatetimeBehavior;

/**
 * This is the model class for table "{{%system_auth_relation}}".
 *
 * @property int $group_id 系统用户组ID
 * @property int $menu_id 系统菜单ID
 * @property string $created_at
 */
class SystemAuthRelation extends \builder\base\BaseActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%system_auth_relation}}';
    }

    /**
     * 重构日期行为配置
     * @return array
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['timestampBehavior'] = [
            'class' => DatetimeBehavior::class,
            'attributes' => [
                self::EVENT_BEFORE_INSERT => ['created_at'],
            ],
        ];

        return $behaviors;
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['group_id', 'menu_id'], 'required'],
            [['group_id', 'menu_id'], 'integer'],
            [['created_at'], 'safe'],
            [['group_id', 'menu_id'], 'unique', 'targetAttribute' => ['group_id', 'menu_id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'group_id' => '系统用户组ID',
            'menu_id' => '系统菜单ID',
            'created_at' => '添加时间',
        ];
    }
}
